package com.ruoyi.quality.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.quality.domain.QualitySale;
import com.ruoyi.quality.service.IQualitySaleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 销售Controller
 * 
 * @author wky
 * @date 2024-06-15
 */
@RestController
@RequestMapping("/quality/sale")
@Tag(name = "【销售】管理")
public class QualitySaleController extends BaseController
{
    @Autowired
    private IQualitySaleService qualitySaleService;

    /**
     * 查询销售列表
     */
    @Operation(summary = "查询销售列表")
    @PreAuthorize("@ss.hasPermi('quality:sale:list')")
    @GetMapping("/list")
    public TableDataInfo list(QualitySale qualitySale)
    {
        startPage();
        List<QualitySale> list = qualitySaleService.selectQualitySaleList(qualitySale);
        return getDataTable(list);
    }

    /**
     * 导出销售列表
     */
    @Operation(summary = "导出销售列表")
    @PreAuthorize("@ss.hasPermi('quality:sale:export')")
    @Log(title = "销售", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QualitySale qualitySale)
    {
        List<QualitySale> list = qualitySaleService.selectQualitySaleList(qualitySale);
        ExcelUtil<QualitySale> util = new ExcelUtil<QualitySale>(QualitySale.class);
        util.exportExcel(response, list, "销售数据");
    }

    /**
     * 获取销售详细信息
     */
    @Operation(summary = "获取销售详细信息")
    @PreAuthorize("@ss.hasPermi('quality:sale:query')")
    @GetMapping(value = "/{saleId}")
    public AjaxResult getInfo(@PathVariable("saleId") Long saleId)
    {
        return success(qualitySaleService.selectQualitySaleBySaleId(saleId));
    }

    /**
     * 新增销售
     */
    @Operation(summary = "新增销售")
    @PreAuthorize("@ss.hasPermi('quality:sale:add')")
    @Log(title = "销售", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QualitySale qualitySale)
    {
        return toAjax(qualitySaleService.insertQualitySale(qualitySale));
    }

    /**
     * 修改销售
     */
    @Operation(summary = "修改销售")
    @PreAuthorize("@ss.hasPermi('quality:sale:edit')")
    @Log(title = "销售", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QualitySale qualitySale)
    {
        return toAjax(qualitySaleService.updateQualitySale(qualitySale));
    }

    /**
     * 删除销售
     */
    @Operation(summary = "删除销售")
    @PreAuthorize("@ss.hasPermi('quality:sale:remove')")
    @Log(title = "销售", businessType = BusinessType.DELETE)
	@DeleteMapping("/{saleIds}")
    public AjaxResult remove(@PathVariable( name = "saleIds" ) Long[] saleIds) 
    {
        return toAjax(qualitySaleService.deleteQualitySaleBySaleIds(saleIds));
    }
}
